#!/usr/bin/env bash

pre:${{pkg.name}}-filesystem() {
    getent group %{nginx_user} > /dev/null || groupadd -r %{nginx_user}
    getent passwd %{nginx_user} > /dev/null || useradd -r -d %{_localstatedir}/lib/nginx -g %{nginx_user} \
        -s /sbin/nologin -c "Nginx web server" %{nginx_user}
    exit 0
}

post:${{pkg.name}}-mod-http-geoip when +geoip() {
    if [ $1 -eq 1 ]; then
    systemctl reload nginx.service >/dev/null 2>&1 || :
    fi
}

post:${{pkg.name}}-mod-http-image-filter() {
    if [ $1 -eq 1 ]; then
    systemctl reload nginx.service >/dev/null 2>&1 || :
    fi
}

post:${{pkg.name}}-mod-http-perl() {
    if [ $1 -eq 1 ]; then
    systemctl reload nginx.service >/dev/null 2>&1 || :
    fi
}

post:${{pkg.name}}-mod-http-xslt-filter() {
    if [ $1 -eq 1 ]; then
    systemctl reload nginx.service >/dev/null 2>&1 || :
    fi
}

post:${{pkg.name}}-mod-mail() {
    if [ $1 -eq 1 ]; then
    systemctl reload nginx.service >/dev/null 2>&1 || :
    fi
}

post:${{pkg.name}}-mod-stream() {
    if [ $1 -eq 1 ]; then
    systemctl reload nginx.service >/dev/null 2>&1 || :
    fi
}

post when +geoip() {
    %systemd_post nginx.service
}

preun() {
    %systemd_preun nginx.service
}

postun() {
    %systemd_postun nginx.service
    if [ $1 -ge 1 ]; then
    /usr/bin/nginx-upgrade >/dev/null 2>&1 || :
    fi
}

